package com.asteros.crypto.ui.applet;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import javax.swing.JApplet;
import javax.swing.SwingUtilities;

import com.asteros.common.util.io.IOUtil;
import com.asteros.crypto.config.AppConfig;
import com.asteros.crypto.ui.swing.MainPanel;

public final class SignerAppletWeb extends JApplet implements ActionListener
{
	public void init()
	{
		System.out.println("SignerApplet.init");
		
		AppConfig.getInstance().defaultClientInit();
		try
		{
			initialize();
			SwingUtilities.invokeAndWait(new Runnable() {
				public void run() { SignerAppletWeb.this.createGUI(); } } );
		}
		catch (Exception e) {
			System.err.println("createGUI didn't successfully complete");
		}
	}

	private void createGUI()
	{
		MainPanel pane = new MainPanel();
		add(pane);
	}

	public void actionPerformed(ActionEvent e)
	{
		System.out.println("actionPerformed!!!");
	}
	
	private void initialize() {

		System.out.println("SignerAppletWeb.initialize>>");
		
		Properties conf = new Properties();

		System.out.println("documentID: " + getParameter("documentID"));
		conf.put("documentID", getParameter("documentID"));

		System.out.println("tspUrl: " + getParameter("tspUrl"));
		conf.put(AppConfig.TSP_SERVER_URL, getParameter("tspUrl"));
		conf.put(AppConfig.TSP_SERVER_URL, "http://www.cryptopro.ru/tsp/tsp.srf");

		conf.put(AppConfig.OCSP_SERVER_URL, "");

		conf.put(AppConfig.CONTAINER_NAME, "Test key");
		conf.put(AppConfig.ETOKEN_PASSWORD, "Q1w2e3r4");
		conf.put(AppConfig.RUTOKEN_PASSWORD, "12345678");
		conf.put(AppConfig.STORE_PATH, "C:\\Projects\\RKK\\testdata\\alice");
		conf.put(AppConfig.SEED_PATH, "C:\\Projects\\RKK\\testdata\\alice");
		conf.put(AppConfig.PKCS12_PFX, "store.pfx");		
		conf.put(AppConfig.PKCS12_PASSWORD, "password");

		AppConfig.getInstance().init(conf);
		
		System.out.println("SignerAppletWeb.initialize<<");
	}
}
